﻿using System;
using Infrastructure;
using Presentation;

namespace WebClient
{
    public partial class WebClientForm : System.Web.UI.Page, IView
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Presenter"] != null)
                ((Presenter)Session["Presenter"]).Rebind(this);
            else
                 Session.Add("Presenter", new Presenter(this, new HtmlLogger()));      
        }

       public string FromValue
        {
            get { return inputValue.Text; }
        }

        public string FromType
        {
            get { return inputType.Text; }
        }

        public string ToType
        {
            get { return outputType.Text; }
        }

        public string ToValue
        {
            set { outputValue.Text = value; }
        }

        public string FileName
        {
            get { return fileName.Text; }
        }

        public string ErrorMessage
        {
            set { errorMassege.Text = value; }
        }

        public string Action
        {
            set
            {
                var i = logList.Items.Count;
                logList.Items.Add(Convert.ToString(i)+" | "+value);
            }
        }

        public event Action OnConvertClick;
        public event Action OnWriteLogToFile;
        public event Action OnTxtClick;
        public event Action OnHtmlClick;

        public void ClearError()
        {
            ErrorMessage = "";
        }

        public ILog CreateTxtLogger()
        {
            return new TxtLogger();
        }
        public ILog CreateHtmlLogger()
        {
            return new HtmlLogger();
        }

        protected void convertButton_Click1(object sender, EventArgs e)
        {
            OnConvertClick();
        }

        protected void writeLogHtml_Click(object sender, EventArgs e)
        {
            OnWriteLogToFile();
        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (RadioButtonList1.SelectedIndex)
            {
                case 0:
                    OnTxtClick();
                    break;
                case 1:
                    OnHtmlClick();
                    break;
            }
        }
    }
}
